#include "List.h"

template<typename ElemType>
Status SqList<ElemType>::InitList()
{
	elem = new ElemType[MAXSIZE];
	if (!elem) exit(OVERFLOW);
	length = 0;
	return OK;
}

template<typename ElemType>
Status SqList<ElemType>::GetElem(int i, ElemType& e)
{
	if (i<1 || i>length) return ERROR;
	e = elem[i - 1];
		return OK;
}

template<typename ElemType>
int SqList<ElemType>::LocationElem(ElemType e)
{
	for (int i = 0; i < length; i++)
		if (elem[i] == e)
			return i + 1;
	return 0;
}

template<typename ElemType>
Status SqList<ElemType>::ListInsert(int i, ElemType e)
{
	if ((i < 1) || (i > length + 1)) return ERROR;
	if (i.length == MAXSIZE) return ERROR;
	for (int j = length - 1; j >= i - 1; j--)
		elem[j + 1] = elem[j];
	elem[i - 1] = e;
	++length;
	return OK;
}

template<typename ElemType>
Status SqList<ElemType>::ListDelete(int i)
{
	if ((i < 1) || (i > length)) return ERROR;
	for (int j = i; j < length - 1; j++)
		elem[j - 1] = elem[j];
	--length;
	return OK;
}

template<typename ElemType>
inline Status LNode<ElemType>::InitList(LNode* L)
{
	L = new LNode;
	L->next = NULL;
	return OK;

}
